<?php


namespace app\controller;

use app\service\CategoryService;
use think\facade\Request;

/**
 * 商品类别
 */
class CategoryController
{
    /**
     * 获取全部父类别
     */
    public function queryAllFatherCategory() {
        return json(CategoryService::queryAllFatherCategory());
    }

    /**
     * 获取该父类别下的全部子类别
     */
    public function queryAllSonCategoryByFather() {
        $param['father_category'] = Request::param('father_category');
        return json(CategoryService::queryAllSonCategoryByFather($param));
    }

    /**
     * 新增父类别
     */
    public function createFatherCategory() {
        $param['father_category'] = Request::param('father_category');
        $param['status'] = 1;
        return json(CategoryService::createFatherCategory($param));
    }

    /**
     * 新增子类别
     */
    public function createSonCategory() {
        $param['father_category'] = Request::param('father_category');
        $param['son_category'] = Request::param('son_category');
        $param['img'] = Request::param('img');
        $param['status'] = 1;
        return json(CategoryService::createSonCategory($param));
    }

    /**
     * 删除父类别
     */
    public function deleFatherCategory() {
        $param['father_category'] = Request::param('father_category');
        return json(CategoryService::deleFatherCategory($param));
    }

    /**
     * 删除子类别
     */
    public function deleSonCategory() {
        $param['father_category'] = Request::param('father_category');
        $param['son_category'] = Request::param('son_category');
        return json(CategoryService::deleSonCategory($param));
    }
}
